package com.wanqing.mapper;

import com.github.pagehelper.Page;
import com.wanqing.annotation.AutoFill;
import com.wanqing.entity.Employee;
import com.wanqing.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     *
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    @AutoFill(OperationType.INSERT)
    @Insert("insert into employee (name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user)" +
            " VALUES (#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void save(Employee employee);

    @Select("<script>" +
            "SELECT * FROM employee " +
            "<where> " +
            "   <if test='name != null and name != \"\"'> " +
            "       name LIKE CONCAT('%', #{name}, '%') " +
            "   </if> " +
            "</where> " +
            "</script>")
    Page<Employee> pageQuery(String name);

    /**
     * 更新指定记录的状态
     * 此方法用于根据给定的ID更新数据库中对应记录的状态
     *
     * @param employee 员工对象，包含需要更新的状态信息
     */
    @AutoFill(OperationType.UPDATE)
    void update(Employee employee);

    /**
     * 根据员工ID获取员工信息
     *
     * @param id 员工ID，用于唯一标识一个员工
     * @return 返回员工对象，包含员工的详细信息
     */
    @Select("select * from employee where id = #{id}")
    Employee getById(Long id);
}
